package com.guchenbo.example.encoding;

import java.io.UnsupportedEncodingException;

/**
 * @Author penglai
 * @Date 2016/10/26.
 */
public class CharsetTest {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "多听FM";

        HexUtils.toHex(s.toCharArray(), "char[]");

        print(s, "ascii");
        print(s, "iso-8859-1");
        print(s, "gb2312");
        print(s, "gbk");
        print(s, "gb18030");
        print(s, "utf-8");
        print(s, "utf-16");

        test(s);
    }

    private static void test(String s) throws UnsupportedEncodingException {
        byte[] utf = s.getBytes("utf-8");
        s = new String(utf, "iso-8859-1");
        System.out.println(s);
        utf = s.getBytes("iso-8859-1");
        System.out.println(new String(utf, "gbk"));


    }

    private static void print(String s, String charset) throws UnsupportedEncodingException {
        HexUtils.toHex(s, s.getBytes(charset), charset);
    }
}
